package com.qf.blog.mybatis;

import org.apache.ibatis.session.SqlSession;

/**
 *存放sqlSession的
 * @author zyt
 * @version 1.0
 */
public class SqlSessionThreadLocal {

    // 使用ThreadLocal来保存SqlSession
    private static ThreadLocal<SqlSession> threadLocal = new ThreadLocal<>();

    // 把SqlSEssion添加到ThreadLocal中
    public static void set(SqlSession sqlSession) {
        threadLocal.set(sqlSession);
    }

    // 从ThreadLocal获取SqlSession
    public static SqlSession get() {
        return threadLocal.get();
    }
}
